xquery version "3.0";

import module namespace back-form = "forms/back-form" at "modules/back-form.xqm";
import module namespace home = "pages/home" at "modules/home.xqm";

declare variable $local:path := request:get-parameter("exist:path", "");
declare variable $local:resource := request:get-parameter("exist:resource", "");
declare variable $local:root := request:get-parameter("exist:root", "");
declare variable $local:controller := request:get-parameter("exist:controller", "");

util:declare-option("exist:serialize", "method=html5 media-type=text/html indent=yes"),
if ($local:path = "/feed") then
    back-form:store()
else if (ends-with($local:resource, ".css")) then 
    response:stream-binary(util:binary-doc(concat("/db/tk/exist-db/media/css/", $local:resource)), "text/css", $local:resource)
else if (ends-with($local:resource, ".js")) then 
    response:stream-binary(util:binary-doc(concat("/db/tk/exist-db/media/js/", $local:resource)), "text/javascript", $local:resource)
else if (starts-with($local:path, "/u_images/")) then 
    response:stream-binary(
        util:binary-doc(concat("/db/tk_data/images/user-images/", substring-after($local:path, "/u_images/"))),
        "image/jpeg", 
        $local:resource
    )
else
    home:html()
(:<html>
    <body>
        <h1>It works!</h1>
        <div><b>path: </b>{$local:path}</div>
        <div><b>resource: </b>{$local:resource}</div>
        <div><b>root: </b>{$local:root}</div>
        <div><b>controller: </b>{$local:controller}</div>
    </body>
</html>:)